/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */

#ifndef __SHORTCUT_MANAGER_H__
#define __SHORTCUT_MANAGER_H__

#include <vector>
#include <algorithm>
#include <stdarg.h>
#include "InputCode.h"

namespace PQBuilder
{
	enum ShortcutType
	{
		SHORTCUT_TYPE_GENERAL,//Include camera shortcut,
		SHORTCUT_TYPE_OBJECT,//After object selected
		SHORTCUT_TYPE_TERRAIN,//After terrain selected
		
		//Add new shortcut type just above this line.
		SHORTCUT_TYPE_COUNT,
	};

	/*Represent a shortcut by output Operation and a list of input keys
	*/
	class Shortcut
	{
	public:
		OpType  Op;//output 
		std::vector<int> Input;//input list

		/*construct a command by a list of input
		@param numInput Input list size.
		*/
		Shortcut(OpType op,int numInput,...);
	};

	inline bool ShortcutGreater(const Shortcut* c1, const Shortcut* c2)
	{
		//more input key's is prefer
		return c1->Input.size() > c2->Input.size();//delibertely sort bigger
	}


	typedef std::vector<Shortcut*> ShortcutList;

	/*Manage the shortcuts,save and load shortcuts info.
	*/
	class ShortcutManager
	{
	public:
		ShortcutManager(std::string name);
		ShortcutManager();//default gen
		void loadDefault();
		void save();//save shortcut to .shortcut file

		inline ShortcutList& getShortcuts(ShortcutType type)
		{
			return _shortcuts[type];
		}

	private:
		//we sort the commands one time,let most input button before 
		inline void sortOps()
		{
			for(int i=0;i<SHORTCUT_TYPE_COUNT;i++){
				std::sort(_shortcuts[i].begin(), _shortcuts[i].end(),ShortcutGreater);
			}
		}

	private:
		std::string _name;//the shortcut configure file name.
		ShortcutList _shortcuts[SHORTCUT_TYPE_COUNT];
	};
}
#endif
